//
//  CellForWater.m
//  PCAForWar
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CellForWater.h"
#import "Model.h"
#import "UIImageView+WebCache.h"


@implementation CellForWater

- (instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.imageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.imageView];
        
        self.labelForTitle = [[UILabel alloc] init];
        self.labelForTitle.backgroundColor = [UIColor clearColor];
        [self.contentView addSubview:self.labelForTitle];
    }
    return self;
}

- (void)dealloc{
    
    [_imageView release];
    [_labelForTitle release];
    [super dealloc];
}

+ (CGFloat)height:(UIImage *)imageT{
    
    CGFloat scale = imageT.size.height / imageT.size.width;
    
    return scale * (([UIScreen mainScreen].bounds.size.width - 30) / 2);
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    self.imageView.frame = CGRectMake(0, 0, self.bounds.size.width, [self.class height:self.imageView.image]);
    self.imageView.layer.cornerRadius = 10;
    self.imageView.layer.masksToBounds = YES;
    
    self.labelForTitle.frame = CGRectMake(0, self.imageView.frame.size.height, self.bounds.size.width, 50);
    self.labelForTitle.numberOfLines = 2;
    self.labelForTitle.textColor = [UIColor whiteColor];
    self.labelForTitle.layer.cornerRadius = 4;
    self.labelForTitle.layer.masksToBounds = YES;
    
    self.labelForTitle.font = [UIFont boldSystemFontOfSize:14];
    
}

- (void)passmodel:(Model *)model {
    
    [self.imageView sd_setImageWithURL:[NSURL URLWithString:model.PicUrl]];
    self.labelForTitle.text = model.Title;
}


@end
